package com.shop.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author : WanS
 * @date : 20:21 2020/11/30
 * 异常捕获,自身不贴增强控制器注解,其他模块需要抛异常时,直接继承这个类即可
 */
public class CommonControllerAdvice {
    //捕获自定义异常
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result handler(BusinessException e) {
        e.printStackTrace();
        e.getMessage();
        return Result.error(e.getCodeMsg());
    }
    //捕获其他系统异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result hanlderDefaultException(Exception e) {
        e.printStackTrace();
        return Result.defaultError();
    }
}
